<?php
namespace app\api\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;

class CatList extends Base{
    public function __construct(\think\App $app) {
        parent::__construct($app);
    }
    public function index()
    {
        //栏目id
        $pid=Request::param("pid",0,"intval");
        $data=Db::name("cat")->where("pid",$pid)->order("sort asc,catid asc")->select();
        foreach($data as $key=>$v){
            $catData=Db::name("cat_data")->find($v['catid']);
            $data[$key]=array_merge($v,$catData);
        }
        $this->success([
            "data"=>$data,
            "total"=>Db::name("cat")->where("pid",$pid)->count(),
        ]);
    }

}
